﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using F1010DB.SecurityServices;
using F1010DB.CustomEntity.Account;
namespace HDVN_F1_101
{
    public partial class frmLogin : Form
    {
        private InitLoadDataServices initLoading = null;
        public frmLogin()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AccountLoginServices loginServices = null;
            AccountLogin loginModel = new AccountLogin();

            loginModel.AccountId = txtAccountId.Text;
            loginModel.Password = txtPassword.Text;

            loginServices = new AccountLoginServices(loginModel);

            List<String> lst = loginServices.checkLogin();

            if (lst == null)
            {
                // Phần này bắt đầu lưu thông tin account

                //Phần này sẽ load tất cả các bảng
                // Danh mục
                // Common
                initLoading = new InitLoadDataServices();
                initLoading.loadDataForMsg();
                initLoading.defineNameLabelList();
                initLoading.initGetListData();
                initLoading.initMasterCommon();
                loginServices.setAccountInfo(txtAccountId.Text);
                // Mở file
                this.Hide();
                frmMainForm f = new frmMainForm();
                f.Show();
                f.WindowState = FormWindowState.Maximized;
                f.Text = "Session for : " + AccountInfo.tenDonVi + " - " + AccountInfo.level;
            }
            else
            {
                //Thất bại
                StringBuilder sb = new StringBuilder();

                foreach(string s in lst)
                {
                    sb.AppendLine(s);
                }

                MessageBox.Show(sb.ToString());
            }

        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            txtAccountId.Text = AccountInfo.unitCode;
            txtPassword.Focus();
        }
    }
}
